/*
 * The MIT License
 *
 * Copyright 2014 Venkat Ram Akkineni.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package org.netbeans.modules.tfsnb.tfvc.workspace;

import java.awt.CardLayout;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JPanel;
import org.netbeans.modules.tfsnb.tfvc.LinkButton;

/**
 *
 * @author Venkat Ram Akkineni
 */
public class SwitchPanel extends javax.swing.JPanel {

    /**
     * Creates new form SwitchPanel
     */
    public SwitchPanel() {
        initComponents();
    }

    public void changePanel(final LinkButton link) {
        CardLayout cl = (CardLayout) bodyPanel.getLayout();
        cl.show(bodyPanel, link.getId());
    }
    
    public void add(final LinkButton linkButton, final JPanel panel) {
        linkButton.addMouseListener(linkButton);
        linksPanel.add(linkButton);
        bodyPanel.add(panel, linkButton.getId());        
        labelToViewMap.put(linkButton, panel);
    }
    
    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The
     * content of this method is always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        bodyPanel = new javax.swing.JPanel();
        linksPanel = new javax.swing.JPanel();

        org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(SwitchPanel.class, "SwitchPanel.jLabel2.text")); // NOI18N

        setLayout(new java.awt.BorderLayout());

        bodyPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        bodyPanel.setLayout(new java.awt.CardLayout());
        add(bodyPanel, java.awt.BorderLayout.CENTER);

        linksPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        linksPanel.setMinimumSize(new java.awt.Dimension(100, 20));
        linksPanel.setPreferredSize(new java.awt.Dimension(136, 20));
        linksPanel.setLayout(new javax.swing.BoxLayout(linksPanel, javax.swing.BoxLayout.LINE_AXIS));
        add(linksPanel, java.awt.BorderLayout.NORTH);
    }// </editor-fold>//GEN-END:initComponents
    
    private final Map<LinkButton, JPanel> labelToViewMap = new HashMap<>();
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel bodyPanel;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel linksPanel;
    // End of variables declaration//GEN-END:variables
}
